package demo05

/**
 * @author xiaoZhao
 * @date 2022/6/30
 * @describe 特质
 */
object Test13_Trait {
  def main(args: Array[String]): Unit = {
    val student = new Student13
    student.sayHello()
    student.study()
    student.dating()
    student.play()
  }
}

class Person13 {
  val name: String = "Person"
  var age: Int = 18

  def sayHello(): Unit = {
    println("hello from :" + name)
  }
}

// 定义特质
trait Yong {
  // 声明抽象和非抽象属性
  var age: Int
  val name: String = "Yong"

  // 声明抽象和非抽象方法
  def play(): Unit = {
    println(s"Yong people $name is playing")
  }

  def dating(): Unit
}

class Student13 extends Person13 with Yong {
  // 重写冲突的属性
  override val name: String = "student"
  // 实现抽象方法
  override def dating(): Unit = println(s"Student $name is dating")

  def study() = println(s"studnt $name is study")

  //
  override def sayHello(): Unit = {
    super.sayHello()
    println(s"hello from: student $name")
  }
}